package genedit.gui.propertyDialogs;



import genedit.gui.GMainFrame;
import genedit.gui.exceptions.RequiredFieldException;
import genedit.gui.propertyDialogs.AbstractDialog.StanjeDijaloga;
import genedit.model.graph.GraphElement;
import genedit.model.graph.classModel.GAttribute;
import genedit.model.graph.classModel.GAttribute.VisibilityType;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;



@SuppressWarnings("serial")
public class PanelDetailAttribute extends AbstractPanelDetail {
	
	private JLabel lblVisibility;
	private JComboBox cmbVisibility;
	String[] visibility;
	
	private AbstractDialog parent;
	
	private JLabel lblType;
	private JTextField txtType;
	
	private JLabel lblName;
	private JTextField txtName;
	
	private JLabel lblPredef;
	private JTextField txtPredef;
	
	private JLabel lblGetter;
	private JLabel lblSetter;
	private JCheckBox chkGetter;
	private JCheckBox chkSetter;
	
	
	public PanelDetailAttribute(StanjeDijaloga mode, AbstractDialog parent, GAttribute attribute) {
		
		setLayout(new BorderLayout());

		Dimension lblDimension = new Dimension(150,20);
		
		Box boxCentar = new Box(BoxLayout.Y_AXIS);
		
		this.parent = parent;
		
		JPanel panVisibility = new JPanel(new FlowLayout(FlowLayout.LEFT));
		lblVisibility = new JLabel(GMainFrame.getInstance().getResourceBundle().getString("lblVisibility"));
		lblVisibility.setPreferredSize(lblDimension);
		visibility = new String [] {"private", "protected", "public"};
		
		cmbVisibility = new JComboBox(visibility);
		cmbVisibility.setEnabled(mode != StanjeDijaloga.BROWSE);
		panVisibility.add(lblVisibility);
		panVisibility.add(cmbVisibility);
		if (!(parent instanceof InterfaceModelDialog))
		boxCentar.add(panVisibility);
		
		JPanel panType = new JPanel(new FlowLayout(FlowLayout.LEFT));
		lblType = new JLabel(GMainFrame.getInstance().getResourceBundle().getString("lblType"));
		lblType.setPreferredSize(lblDimension);
		txtType = new JTextField(10);
		txtType.setEnabled(mode != StanjeDijaloga.BROWSE);
		panType.add(lblType);
		panType.add(txtType);
		boxCentar.add(panType);
		

		JPanel panName = new JPanel(new FlowLayout(FlowLayout.LEFT));
		lblName = new JLabel(GMainFrame.getInstance().getResourceBundle().getString("lblName"));
		lblName.setPreferredSize(lblDimension);
		txtName = new JTextField(10);
		txtName.setEnabled((mode != StanjeDijaloga.BROWSE));
		panName.add(lblName);
		panName.add(txtName);
		boxCentar.add(panName);
		
		JPanel panPredef = new JPanel(new FlowLayout(FlowLayout.LEFT));
		lblPredef = new JLabel(GMainFrame.getInstance().getResourceBundle().getString("lblPredef"));
		lblPredef.setPreferredSize(lblDimension);
		txtPredef = new JTextField(10);
		txtPredef.setEnabled((mode != StanjeDijaloga.BROWSE));
		panPredef.add(lblPredef);
		panPredef.add(txtPredef);
		boxCentar.add(panPredef);
		
		JPanel panGetter = new JPanel(new FlowLayout(FlowLayout.LEFT));
		lblGetter = new JLabel("Get");
		lblGetter.setPreferredSize(new Dimension(50, 20));
		chkGetter = new JCheckBox();
		chkGetter.setSelected(attribute.isGetAttribute());
		panGetter.add(lblGetter);
		panGetter.add(chkGetter);
		if (!(parent instanceof InterfaceModelDialog))
		boxCentar.add(panGetter);
		
		JPanel panSetter = new JPanel(new FlowLayout(FlowLayout.LEFT));
		lblSetter = new JLabel("Set");
		lblSetter.setPreferredSize(new Dimension(50, 20));
		chkSetter = new JCheckBox();
		chkSetter.setSelected(attribute.isSetAttribute());
		panSetter.add(lblSetter);
		panSetter.add(chkSetter);
		if (!(parent instanceof InterfaceModelDialog))
		boxCentar.add(panSetter);
		


		add(boxCentar,BorderLayout.CENTER);
		
	}
	




	public JComboBox getCmbVisibility() {
		return cmbVisibility;
	}





	public JCheckBox getChkGetter() {
		return chkGetter;
	}





	public void setChkGetter(JCheckBox chkGetter) {
		this.chkGetter = chkGetter;
	}





	public JCheckBox getChkSetter() {
		return chkSetter;
	}





	public void setChkSetter(JCheckBox chkSetter) {
		this.chkSetter = chkSetter;
	}





	public JTextField getTxtPredef() {
		return txtPredef;
	}





	public void setTxtPredef(JTextField txtPredef) {
		this.txtPredef = txtPredef;
	}





	public void setCmbVisibility(JComboBox cmbVisibility) {
		this.cmbVisibility = cmbVisibility;
	}





	public JTextField getTxtType() {
		return txtType;
	}





	public void setTxtType(JTextField txtType) {
		this.txtType = txtType;
	}





	public JTextField getTxtName() {
		return txtName;
	}





	public void setTxtName(JTextField txtName) {
		this.txtName = txtName;
	}





	public void proveriIspravnostPodataka() throws RequiredFieldException {
		
		if (txtType.getText().trim().equals("")) {
			txtType.setBackground(Color.RED);
			//ok = false;
			txtType.addKeyListener(new KeyListener() {
				
				@Override
				public void keyTyped(KeyEvent e) {
					
					
				}
				
				@Override
				public void keyReleased(KeyEvent e) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void keyPressed(KeyEvent e) {
					if (e.isActionKey() || e.getKeyCode()==KeyEvent.VK_ENTER || e.getKeyCode()==KeyEvent.VK_BACK_SPACE)
						return;
					
					else
						txtType.setBackground(Color.WHITE);
			//		ok = true;
					
				}
			});
			RequiredFieldException rfe = new RequiredFieldException(
					);
			throw rfe;
		}
		
		if (txtName.getText().trim().equals("")) {
			txtName.setBackground(Color.RED);
		//	ok = false;
			txtName.addKeyListener(new KeyListener() {
				
				@Override
				public void keyTyped(KeyEvent e) {
					
					
				}
				
				@Override
				public void keyReleased(KeyEvent e) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void keyPressed(KeyEvent e) {
					if (e.isActionKey() || e.getKeyCode()==KeyEvent.VK_ENTER || e.getKeyCode()==KeyEvent.VK_BACK_SPACE)
						return;
					
					else
						txtName.setBackground(Color.WHITE);
			//		ok = true;
					
				}
				
			});
			RequiredFieldException rfe = new RequiredFieldException(
					);
			throw rfe;
		}
		
		if(parent instanceof InterfaceModelDialog)
		if (txtPredef.getText().trim().equals("")) {
			txtPredef.setBackground(Color.RED);
		//	ok = false;
			txtPredef.addKeyListener(new KeyListener() {
				
				@Override
				public void keyTyped(KeyEvent e) {
					
					
				}
				
				@Override
				public void keyReleased(KeyEvent e) {
					// TODO Auto-generated method stub
					
				}
				
				@Override
				public void keyPressed(KeyEvent e) {
					if (e.isActionKey() || e.getKeyCode()==KeyEvent.VK_ENTER || e.getKeyCode()==KeyEvent.VK_BACK_SPACE)
						return;
					
					else
						txtPredef.setBackground(Color.WHITE);
			//		ok = true;
					
				}
				
			});
			RequiredFieldException rfe = new RequiredFieldException(
					);
			throw rfe;
		}
		
	
		//return ok;
	}


	}
	

